package com.synyi.controllers;

import com.synyi.entity.DonorEntity;
import com.synyi.entity.DonorSelectEntity;
import com.synyi.entity.Result;
import com.synyi.service.DonorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController("donor")
@Slf4j
public class DonorController {
    @Autowired
    private DonorService donorService;

    /**
     * 供体信息添加
     * @param donorEntity
     * @return
     */
    @Transactional
    @PutMapping("/add")
    public Result addDonor(@RequestBody DonorEntity donorEntity){
        log.info("addDonor方法启动， 参数为：{}", donorEntity);
        return donorService.addDonor(donorEntity);
    }

    /**
     * 修改工体信息
     * @param donorEntity
     * @return
     */
    @Transactional
    @PostMapping("/update")
    public Result updateDonor(@RequestBody DonorEntity donorEntity){
        log.info("updateDonor方法启动， 参数为：{}", donorEntity);
        return donorService.updateDonor(donorEntity);
    }

    @GetMapping("/select")
    public Result selectDonor(@RequestBody DonorSelectEntity donorSelectEntity){
        log.info("selectDonor方法启动， 参数为：{}", donorSelectEntity);
        return donorService.selectDonor(donorSelectEntity);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteDonor(@PathVariable Long id){
        log.info("deleteDonor方法启动， 参数为：{}", id);
        return donorService.deleteDonorById(id);
    }
}
